package com.attms.controller;


import com.attms.controller.utils.R;
import com.attms.domain.Absent;
import com.attms.service.IAbsentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Team
 * @since 2022-12-18
 */
@RestController
@RequestMapping("/absent")
public class AbsentController {
    @Autowired
    private IAbsentService iAbsentService;

    // 根据请假条id获取请假信息
    @GetMapping("/A/{id}")
    public R getByAID(@PathVariable Integer id){
        return new R(true, iAbsentService.searchAbsenceByAID(id));
    }

    // 根据员工id获取请假信息
    @GetMapping("/E/{id}")
    public R getByEID(@PathVariable Integer id){
        return new R(true, iAbsentService.searchAbsenceByEID(id));
    }

    // 新增请假信息
    @PostMapping
    public R saveNewAbsence(@RequestBody Absent absent){
        return new R(iAbsentService.createAbsence(absent));
    }

    // 更改请假信息
    @PutMapping
    public R updAbsence(@RequestBody Absent absent){
        return new R(iAbsentService.updateAbsence(absent));
    }

    // 根据请假条id删除请假条
    @DeleteMapping("/{id}")
    public R delAbsence(@PathVariable Integer id){
        return new R(iAbsentService.deleteAbsence(id));
    }
}

